<html>
<head>
<style>
.pagination {
	float: left;
	margin: 10px;
	border: 1px solid;
	padding: 5px;
}
.paging{
	float: left;
}
a {
	margin: 10px;
}
tr,td {
	border: 1px solid;
}
</style>
</head>
<body>
<?php
$i = isset($_GET['page']) ? $_GET['page'] : 1;
$username="root";
$password="";$database="employees";
$link = mysql_connect("localhost", "root", "") 
   or die("Could not connect : " . mysql_error()); 
echo "Connected successfully";
mysql_select_db("employees") or die("Could not select database"); 
/* Performing SQL query */   
@mysql_select_db($database) or die( "Unable to select database");
$per_page = 30;
$offset = $i*$per_page;
$query = "SELECT * FROM `employees` ORDER BY emp_no ASC LIMIT $per_page OFFSET $offset";
echo $query;
$result = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<table>\n"; 
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
   echo "\t<tr>\n"; 
   foreach ($line as $col_value) { 
	echo "<td>";
       //echo "<img src=\"../../moods/$col_value\">";
	   echo $col_value . "</td>";
   } 
   echo "\t</tr>\n"; 
} 
echo "</table>\n"; 

$query = "SELECT COUNT(*) FROM employees";
$result = mysql_query($query);
/* Free resultset */ 
$values = mysql_fetch_array($result);
/*
$query = "DESCRIBE employees";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
print_r($line);
*/
mysql_free_result($result); 
mysql_close($link);
$pages = ceil($values[0] / $per_page);

if ($i > 1) {
?>
	<div class="paging">
	<a style="float:left" href="test.php?page=<?php echo $i-1; ?>">Back</a>
	<a style="float:left" href="test.php?page=1">First</a>
<?php } 
for ($j=$i; $j<$pages; $j++) {
	if ($j > $i + 5 && $j < $pages - 5)
		continue;
	echo "<a class=\"pagination\" href=\"test.php?page=$j\">$j</a>";
	if ($j == $i + 5)
		echo "<div class=\"pagination\"> ...</div>";
}
if ($i < $pages-1) { ?>
	<a href="test.php?page=<?php echo $i+1; ?>">Next</a>
	<a href="test.php?page=<?php echo $pages-1; ?>">Last</a>
	</div>
<?php 
}
?>
</body>
</html>